package gq.example.mapper;

import com.github.pagehelper.Page;
import gq.example.annotation.AutoFill;
import gq.example.dto.QuestionPageQueryDto;
import gq.example.entity.Question;
import gq.example.enumeration.OperationType;
import gq.example.vo.QuestionVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface QuestionMapper {

    /**
     * 添加问题
     * @param question
     */
    @AutoFill(value = OperationType.INSERT)
    @Insert("insert into question(type,sector_id,headline,description,status,create_user,create_time) values(#{type},#{sector_id},#{headline},#{description},#{status},#{createUser},#{createTime})")
    void addQuestion(Question question);

    /**
     * 历史记录（意见查看）
     * @param questionPageQueryDto
     * @return
     */
    Page<QuestionVo> historyPageQuery(QuestionPageQueryDto questionPageQueryDto);

    /**
     * 意见查看（分页查询）
     * @param questionPageQueryDto
     * @return
     */
    Page<Question> listPageQuery(QuestionPageQueryDto questionPageQueryDto);

    /**
     * 更新问题信息
     * @param question
     */
    void update(Question question);

    /**
     * 根据id查询创建者
     * @param id
     * @return
     */
    @Select("select create_user from question where id = #{id}")
    Integer getCreateUserById(Integer id);

    /**
     * 查看问题(前端回显)
     * @param id
     * @return
     */
    @Select("select  sector_id as sectorId, type, headline from question where id = #{id} ")
    QuestionVo viewQuestion(Integer id);

    /**
     * 获取问题内容
     * @param id
     * @return
     */
    @Select("select description from question where id = #{id}")
    String getContentById(Integer id);
}

